package com.ag.hmk.dao;

import java.sql.SQLException;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;

import com.ag.dao.TbUnitDAO;

public class HmkUnitDAO extends TbUnitDAO {
	private static final Log log = LogFactory.getLog(HmkUnitDAO.class);

	/*
	 * 记录总数
	 */
	public List queryCount(final String hql) throws Exception {
		return getHibernateTemplate().executeFind(new HibernateCallback() {
			public Object doInHibernate(Session s) throws HibernateException,
					SQLException {
				Query query = s.createQuery(hql);
				List list = query.list();
				return list;
			}
		});
	}
	
	/*
	 * 分页查询
	 */
	public List queryList(final String hql, final int firstRow, final int maxRow) throws Exception {
		return getHibernateTemplate().executeFind(new HibernateCallback() {
			public Object doInHibernate(Session s) throws HibernateException,
					SQLException {
				Query query = s.createQuery(hql);
				query.setFirstResult(firstRow);
				query.setMaxResults(maxRow);
				List list = query.list();
				return list;
			}
		});
	}

	
}
